package mm.chenchen.modules.script.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import mm.chenchen.modules.script.dao.model.request.ScriptRunHisQuery;
import mm.chenchen.modules.script.entity.ScriptRunHis;
import mm.chenchen.modules.script.service.ScriptRunHisService;
import mm.chenchen.utils.PageUtils;
import mm.chenchen.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author
 * @email
 * @date 2021-07-29 10:50:49
 */
@RestController
@Api(tags = "运行历史管理")
@RequestMapping("reptile/scriptrunhis")
@CrossOrigin
public class ScriptRunHisController {
    @Autowired
    private ScriptRunHisService service;


    /**
     * 列表
     */
    @ApiOperation(value = "分页检索", notes = "")
    @PostMapping("/list")
    //@RequiresPermissions("reptile:scriptpythonrunhis:list")
    public R findPage(@RequestBody ScriptRunHisQuery param) {
        return service.findPage(PageUtils.getPage(param), param);
    }


    /**
     * 信息
     */
    @ApiOperation(value = "单个检索 ", notes = "")
    @GetMapping(value = "/{objId}", produces = "application/json")
    //@RequiresPermissions("reptile:scriptpythonrunhis:info")
    public R getById(@ApiParam(name = "objId", value = "") @PathVariable Long objId) {
        return service.getById(objId);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "新增", notes = "")
    @PostMapping(value = "", produces = "application/json")
    //@RequiresPermissions("reptile:scriptpythonrunhis:save")
    public R save(@RequestBody ScriptRunHis param) {
        return service.saveInfo(param);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "更新", notes = "")
    @PutMapping(value = "/{objId}", produces = "application/json")
    //@RequiresPermissions("reptile:scriptpythonrunhis:update")
    public R update(@ApiParam(name = "objId", value = "") @PathVariable Long objId, @RequestBody ScriptRunHis param) {
        param.setId(objId);
        return service.update(param);
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除", notes = "")
    @DeleteMapping(value = "/{objId}", produces = "application/json")
    //@RequiresPermissions("reptile:scriptpythonrunhis:delete")
    public R deleteById(@ApiParam(name = "objId", value = "") @PathVariable Long objId) {
        return service.deleteById(objId);
    }

    @ApiOperation(notes = "下载文件", value = "下载文件单个")
    @GetMapping(value = "/file/{objId}")
    public void downloadFileFromMinio(@ApiParam(name = "objId", value = "") @PathVariable Long objId, HttpServletResponse response) throws Exception {
        service.downLoadFromMinio(objId,response);
    }
}
